import 'package:flutter/material.dart';

class File09HomeNav extends StatelessWidget {
  const File09HomeNav({super.key, this.navList = const []});
  final List navList;

  @override
  Widget build(BuildContext context) {
    return GridView.builder(
      padding: EdgeInsets.only(left: 8, right: 8, top: 8, bottom: 2),
      gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
        crossAxisCount: 5,
        mainAxisSpacing: 0,
        crossAxisSpacing: 0,
        childAspectRatio: 1,
      ),
      itemCount: navList.length,
      // 处理listview嵌套报错
      shrinkWrap: true,
      physics: const NeverScrollableScrollPhysics(),
      // 构造子元素
      itemBuilder: (BuildContext context, int index) {
        return Container(
          padding: EdgeInsets.only(top: 6),
          child: Column(
            spacing: 4,
            children: [
              Image.network(
                navList[index]['imgUrl'],
                height: 40,
                fit: BoxFit.cover,
              ),
              Text(navList[index]['text'], style: TextStyle(fontSize: 13)),
            ],
          ),
        );
      },
    );
  }
}
